@page "/app/{AppId}/settings/secret-key-created"

@using System.Text

@inherits BaseApplicationPage

@inject NavigationManager NavigationManager

<Page Title="Secret Key Created">
    <Panel>
        <CopyInputField Value="@ApiKey" Title="Secret Key" Type="password" />
        <Alert Style="@ContextualStyles.Danger">
            Secret keys are only shown once. Not saving your secret key will require it to be recreated when lost.
        </Alert>
        <div>
            <a
                id="go-to-app-settings-btn"
                class="btn-primary"
                href="/app/@(AppId)/settings">
                Go To Application Settings
            </a>
        </div>
    </Panel>
</Page>

@code {
    [SupplyParameterFromQuery(Name = "EncodedApiKey")]
    public string? EncodedApiKey { get; set; }
    
    public string ApiKey { get; private set; }

    protected override void OnInitialized()
    {
        if (string.IsNullOrEmpty(EncodedApiKey))
        {
            NavigationManager.NavigateTo($"/app/{AppId}/settings");
        }
        
        ApiKey = Encoding.UTF8.GetString(Base64Url.Decode(EncodedApiKey));
    }  
}